<%@page import="dao.SukienDAO"%>
<%@page import="model.Sukien"%>
<%@page import="dao.MuctintucDAO"%>
<%@page import="model.Muctintuc"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<jsp:include page="Admin_includes/header.jsp"></jsp:include>

<div id="center-content">
	<div id="left">
		<jsp:include page="Admin_includes/left.jsp"></jsp:include>
	</div>
	<!-- end left -->

	<%
		ArrayList<Muctintuc> listMuctintuc = MuctintucDAO.select();
		ArrayList<Sukien> listSukien = SukienDAO.select();

		String hinh = "", title = "", title_khongdau = "", muctintuc = "", ngayviet = "", thoigianviet = "", sukien = "", noidung = "";
		String err_image = "", err_title = "", err_titlekhongdau = "", err_muctintuc = "", err_ngayviet = "", err_thoigianviet = "", err_sukien = "", err_noidung="";
		noidung = (String) request.getAttribute("noidung");
		
		// Hinh
		if (request.getAttribute("hinh") != null) {
			hinh = (String) request.getAttribute("hinh");
		}
		//tiêu đề
		if (request.getAttribute("title") != null) {
			title = (String) request.getAttribute("title");
		}
		//tiêu đề không dấu
		if (request.getAttribute("title_khongdau") != null) {
			title_khongdau = (String) request.getAttribute("title_khongdau");
		}
		//Muc tin tức
		if (request.getAttribute("muctintuc") != null) {
			muctintuc = (String) request.getAttribute("muctintuc");

		}
		//Ngày Viết
		if (request.getAttribute("ngayviet") != null) {
			ngayviet = (String) request.getAttribute("ngayviet");

		}
		//Thời gian
		if (request.getAttribute("thoigianviet") != null) {
			thoigianviet = (String) request.getAttribute("thoigianviet");
		}
		//Sự kiện
		if (request.getAttribute("sukien") != null) {
			sukien = (String) request.getAttribute("sukien");

		}
		//Nội dung
		if (request.getAttribute("noidung") != null) {
			noidung = (String) request.getAttribute("noidung");
		}else{
			noidung="";
		}
		

		//Lỗi Hình Ảnh
		if (request.getAttribute("err_image") != null) {
			err_image = (String) request.getAttribute("err_image");

		}
		//Lỗi tiêu đề
		if (request.getAttribute("err_title") != null) {
			err_title = (String) request.getAttribute("err_title");
		}
		//Lỗi tiêu đề không dấu
		if (request.getAttribute("err_titlekhongdau") != null) {
			err_titlekhongdau = (String) request.getAttribute("err_titlekhongdau");
		}
		//Lỗi Muc tin tức
		if (request.getAttribute("err_muctintuc") != null) {
			err_muctintuc = (String) request.getAttribute("muctintuc");

		}
		//Lỗi Ngày Viết
		if (request.getAttribute("err_ngayviet") != null) {
			err_ngayviet = (String) request.getAttribute("err_ngayviet");

		}
		//Lỗi Thời gian
		if (request.getAttribute("err_thoigianviet") != null) {
			err_thoigianviet = (String) request
					.getAttribute("err_thoigianviet");
		}
		//Lỗi Sự kiện
		if (request.getAttribute("err_sukien") != null) {
			err_sukien = (String) request.getAttribute("err_sukien");

		}
		//Lỗi Nội dung
		if (request.getAttribute("err_noidung") != null) {
			err_noidung = (String) request.getAttribute("err_noidung");
		}
	%>


	<div id="right">
		<form action="Xulythemtintuc" method="post" class="themtintuc">
			<fieldset>
				<legend> Thêm tin tức </legend>
				<br /> <label> User id </label> <br /> <input type="text" readonly
					value="" /> <br /> <label> Hình </label> <br /> <input
					type="text" name="hinh" value="<%=hinh%>"> <br /> <label
					style="color: red;"><%=err_image%></label><br /> <label>Title</label>
				<br />
				<input type="text" name="title" value="<%=title%>"> <br />
				<label style="color: red;"><%=err_title%></label><br /> <label>Title
					không dấu </label><br /> <input type="text" name="title_khongdau"
					value="<%=title_khongdau%>"> <br /> 
					<label style="color: red;"><%=err_titlekhongdau%></label><br /> 
					<label>Muctintuc-id</label>
				<br /> 
				<select name="muctintuc">
					<%
						for (Muctintuc muctintucother : listMuctintuc) {
					%>
					<%
						String idmuctintuc = muctintucother.getIdmuctintuc() + "";
					%>
					<option value="<%=muctintucother.getIdmuctintuc()%>"
						<%if (idmuctintuc.equalsIgnoreCase(muctintuc)) {%>
						selected="selected" <%}%>>
						<%=muctintucother.getTenmuctintuc()%></option>
					<%
						}
					%>
				</select> <br /> <label> Ngày viết </label> <br /> <input type="date"
					min="2000-01-01" min="2014-01-01" value="<%=ngayviet%>"
					name="ngayviet"> <br /> <label style="color: red;"><%=err_ngayviet%></label><br />

				<label>Thời gian </label> <br /> <input type="time"
					value="<%=thoigianviet%>" name="thoigianviet"> <br /> <label
					style="color: red;"><%=err_thoigianviet%></label><br /> <label>
					Sự kiện </label> <br /> 
					<select name="sukien">
					<option value="NO"></option>
					<%
						for (Sukien sukienother : listSukien) {
							
					%>
					<%
						String sukienid = sukienother.getSukienid();
					%>

					<option value="<%=sukienother.getSukienid() %>" <%if (sukienid.equalsIgnoreCase(sukien)) {%>
						selected="selected"
						<%
							}
						%>
							>
						<%=sukienother.getTensukien()%></option>
					<%
						}
					%>
				</select> 
				<br /> <br /> 
				<label> Nội dung </label> <br />
				
				<textarea name="noidung" ><%=noidung%></textarea><br/>
				<label style="color: red;"><%=err_noidung%></label><br /> 
				<br /> <input type="submit" name="command" value="Add"
					class="buttonluu" />

			</fieldset>
		</form>
	</div>
	<!-- end right -->




</div>
<!-- end center-content-->
<jsp:include page="Admin_includes/footer.jsp"></jsp:include>